home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Robocode / robocode-setup-1.0.7.jar / extract.jar / robots / sample / SpinBot.java < prev    next >
Encoding:
Java Source  |  2005-02-18  |  967 b   |  44 lines

  1. package sample;
  2. import robocode.*;
  3. /**
  4.  * SpinBot - a sample robot by Mathew Nelson
  5.  * 
  6.  * Moves in a circle, firing hard when an enemy is detected
  7.  */
  8. public class SpinBot extends AdvancedRobot {
  9.  
  10.     /**
  11.      * SpinBot's run method - Circle
  12.      */
  13.     public void run() {
  14.           while (true) {
  15.             // Tell the game that when we take move,
  16.             //  we'll also want to turn right... a lot.
  17.             setTurnRight(10000);
  18.             // Limit our speed to 5
  19.             setMaxVelocity(5);
  20.             // Start moving (and turning)
  21.             ahead(10000);
  22.             // Repeat.
  23.           } 
  24.     }
  25.     
  26.     /**
  27.      * onScannedRobot: Fire hard!
  28.      */
  29.     public void onScannedRobot(ScannedRobotEvent e) {
  30.       fire(3);
  31.     }
  32.     
  33.     /**
  34.      * onHitRobot:  If it's our fault, we'll stop turning and moving,
  35.      *              so we need to turn again to keep spinning.
  36.      */
  37.     public void onHitRobot(HitRobotEvent e) {
  38.         if (e.getBearing() > -10 && e.getBearing() < 10)
  39.             fire(3);
  40.         if (e.isMyFault())
  41.             turnRight(10);
  42.     }
  43. }
  44.